package Thread;

/*
 * 当一个线程调用Sleep方法处于睡眠阻塞的过程中，吐过该县城的interrupt()方法被调用
 * name该线程会立即中断睡眠阻塞并在sleep方法在这里抛出中断异常
 * */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread lin = new Thread() {
            @Override
            public void run() {
                System.out.println("睡会睡会~");
                try {
                    /*
                     * lin线程调用sleep方法后会进入到睡眠阻塞的状态，期间如果lin线程的interrupt方法
                     * 被调用的话，就会在sleep方法这里抛出中断异常 并且直接结束sleep阻塞并调到catch块中
                     * */
                    Thread.sleep(10000000);
                } catch (InterruptedException e) {
                    System.out.println("嘛呢！嘛呢！嘛呢！破了相了都");
                }
                System.out.println("醒来了");
            }
        };

        Thread huang = new Thread() {
            @Override
            public void run() {
                System.out.println("大哥，开砸~");
                for (int i = 0; i < 5; i++) {
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println("80");
                }
                /*
                 * interrupt()强制唤醒当前线程
                 * */
                lin.interrupt();
                System.out.println("大哥，搞定！");
            }
        };

        lin.start();
        huang.start();

    }
}
